package com.project.class3_28;

import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) {
        X x = new X();
        Class classX = X.class;
        try {
//            Method m = classX.getMethod("test");
//            m.invoke(x);
            Method m = classX.getMethod("add",int.class,int.class);
            Object returnObj = m.invoke(x,2,3);
            System.out.println(returnObj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
class X {
    public X() {
    }

    public void test(){
        System.out.println("test方法");
    }
    public int add(int a,int b){
        return a+b;
    }
}